package cn.senjoeson.triper.base;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import cn.senjoeson.mylibrary.utils.AppUtils;
import cn.senjoeson.triper.activity.MainActivity;

/**
 * Created by senjoeson on 2018/1/7.
 */

public abstract class BaseFragment extends LazyFragment {

    private View mViewRoot;
    Unbinder unbinder;

    @Override
    protected View initViews(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mViewRoot = inflater.inflate(setContentResId(), container, false);
        unbinder = ButterKnife.bind(this, mViewRoot);
        return mViewRoot;
    }

    @Override
    protected void initData() {
        initView();
        initSetData();
        initListener();
    }



    protected abstract int setContentResId();

    protected abstract void initView();

    protected abstract void initSetData();
    protected abstract void initListener();


    public void startActivity(Class<? extends BaseActivity> clazz) {
        startActivity(new Intent(AppUtils.getContext(), clazz));
    }

    /**
     * 拿到MainActivity的引用
     */
    public MainActivity getMainActivity() {
        return (MainActivity) (getActivity());
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
